package com.jsmile.cloud.authc.api.res;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import cn.hutool.core.collection.CollectionUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2019年04月01日 04:47:15
 */
@Getter
@Setter
@ApiModel
public class ResSysRoleResources implements java.io.Serializable {

    @ApiModelProperty(value = "用户信息")
    private ResSysUser sysUser;

    @ApiModelProperty(value = "角色集合")
    private List<ResSysRole> roles;

    @ApiModelProperty(value = "权限集合")
    private List<ResSysResources> permissions;

    public List<String> getStringPers() {
        List<String> sRoles = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(roles)) {
            roles.stream().forEach(x -> {
                if (!StringUtils.isEmpty(x.getRoleCode())) {
                    sRoles.add(x.getRoleCode());
                }
            });
        }
        if (CollectionUtil.isNotEmpty(permissions)) {
            permissions.stream().forEach(x -> {
                if (!StringUtils.isEmpty(x.getPermCode())) {
                    sRoles.add(x.getPermCode());
                }
            });
        }
        return sRoles;
    }
}
